<template>
  <div class="personalSettingCompile_container pr-1 pl-1">
		<div class="personalSettingCompile_container_inp">
			<input type="text" v-model="val" v-if="type == 'name'">
			<textarea name="sign" v-model="val" v-else></textarea>
		</div>
			<button @click="saveClick">{{ type == 'name'? $t('保存') : $t('保存签名') }}</button>
	</div>
</template>

<script>
import { updateUserInfo } from "@/request/personalCenter"
export default {
	name: 'PersonalSettingCompile',
	data(){
		return{
			val: '',
			type: ''
		}
	},
	mounted(){
		this.val = this.$route.params.value
		this.type = this.$route.params.type
		// console.log(this.$route.params.value)
	},
	methods: {
		saveClick(){
			// 点击保存后调取保存接口
			// 根据不同type进行保存
			// 完成后返回路由
			let obj = {}
			if(this.type == 'sign'){
				// 更改签名
				obj.bio = this.val
			}else{
				// 更改用户名
				obj.nickname = this.val
			}
			console.log(obj)
			updateUserInfo(obj).then(res=>{	
				if(res.code == 1){
					this.$toast.success(this.$t("更改成功"))
					this.$router.go(-1)
					// this.$router.replace({
					// 	name: "PersonalSetting",
					// 	params: { value: this.val , type: this.type }
					// })
					
				}else{
					this.$toast.fail(this.$t("更改失败"))
				}
			})
		}
	}
}
</script>

<style>

</style>